//
//  SettingViewController.m
//  UEHtml-iOS
//
//  Created by ShadowKnight on 13-10-2.
//  Copyright (c) 2013年 Qun He. All rights reserved.
//

#import "SettingViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "UIConstanstDefine.h"
#import "HomeViewController.h"

@interface SettingViewController ()

@end

@implementation SettingViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    [self setTitle:@"设 置"];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    [self initNavigationBar];
    [self msgRecievedSetting];
    
    
}

-(void)initNavigationBar
{
    UIButton *drawerBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 7, 38, 32)];
    [drawerBtn setBackgroundImage:[UIImage imageNamed:@"Drawer_button_normal.png"] forState:UIControlStateNormal];
    [drawerBtn setBackgroundImage:IMAGE_BY_NAMED(@"Drawer_button_select.png") forState:UIControlStateHighlighted];
    [drawerBtn addTarget:self action:@selector(leftBarBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:drawerBtn];
    
    self.navigationController.navigationBar.tintColor = RGBCOLOR(92, 187, 13);//[UIColor greenColor];
}

- (void)leftBarBtnTapped:(id)sender {
    [SHARE_APPDELEGATE makeLeftViewVisible];
    AppDelegate* aDelegate = SHARE_APPDELEGATE;
    aDelegate.navController.viewControllers = [NSArray arrayWithObject:aDelegate.homeVC];
    [aDelegate.homeVC moveToRightSide];
}

-(void)msgRecievedSetting
{
    UIImageView* settingFrame=[[UIImageView alloc] initWithFrame:CGRectMake(10, 12, 300, 88)];//[[UIImageView alloc] initWithFrame:self.view.frame];
    [settingFrame setImage:IMAGE_BY_NAMED(@"setting_Info_frame.png")];
    UIImageView* lineView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 41.5, 300, 1)];
    [lineView setImage:IMAGE_BY_NAMED(@"setting_Info_separated_line.png")];
    [settingFrame addSubview:lineView];
    [settingFrame setUserInteractionEnabled:YES];
    
    [self.view addSubview:settingFrame];
#if 0
    self.view.backgroundColor=[UIColor whiteColor];
    
    UIGraphicsBeginImageContext(settingFrame.frame.size);
    [settingFrame.image drawInRect:CGRectMake(0, 0, settingFrame.frame.size.width, settingFrame.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 0.5);
    CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGPoint poins[] = {CGPointMake(10, 5),CGPointMake(310, 5),CGPointMake(310, 85),CGPointMake(10, 85)};
    CGContextAddLines(UIGraphicsGetCurrentContext(),poins,4);
    CGContextClosePath(UIGraphicsGetCurrentContext());
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    
    //----Draw a line in mid---//
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 10, 45);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 310, 45);
    CGContextClosePath(UIGraphicsGetCurrentContext());
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    
    settingFrame.image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
#endif//0
    
    
    UILabel* desc1 = [[UILabel alloc] initWithFrame:CGRectMake(13, 12.8, 150, 16)];
    [desc1 setBackgroundColor:[UIColor clearColor]];
    [desc1 setText:@"接收/取消消息提醒"];
    [desc1 setFont:[UIFont systemFontOfSize:16.0f]];
    [settingFrame addSubview:desc1];
    
    UIButton* switchBtn = [[UIButton alloc] initWithFrame:CGRectMake(134+77, 4, 77, 32)];
    [switchBtn setImage:IMAGE_BY_NAMED(@"setting_push_btn_normal_bg.png") forState:UIControlStateNormal];
    [switchBtn setImage:IMAGE_BY_NAMED(@"setting_push_btn_sel_bg.png") forState:UIControlStateSelected];
    UIImageView* pointImg = [[UIImageView alloc] initWithFrame:CGRectMake(45, 0, 32, 32)];
    [pointImg setImage:IMAGE_BY_NAMED(@"setting_push_btn_point.png")];
    [pointImg setUserInteractionEnabled:NO];
    pointImg.tag = 5001;
    [switchBtn addTarget:self action:@selector(changePushStatus:) forControlEvents:UIControlEventTouchUpInside];
    [switchBtn addSubview:pointImg];
    [settingFrame addSubview:switchBtn];
    
    UILabel* desc2 = [[UILabel alloc] initWithFrame:CGRectMake(13, 12.8+41.5, 150, 16)];
    [desc2 setBackgroundColor:[UIColor clearColor]];
    [desc2 setText:@"消息接收时段"];
    [desc2 setFont:[UIFont systemFontOfSize:16.0f]];
    [settingFrame addSubview:desc2];
    
    UILabel* desc3 = [[UILabel alloc] initWithFrame:CGRectMake(13+150, 12.8+41.5, 150, 16)];
    [desc3 setBackgroundColor:[UIColor clearColor]];
    [desc3 setText:@"9：00 至 21：00"];
    [desc3 setFont:[UIFont systemFontOfSize:16.0f]];
    [settingFrame addSubview:desc3];
    
    UIButton* aboutBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 125, 300, 40)];
    [aboutBtn setBackgroundImage:createImageWithColor(HEXCOLOR(0x6bc40d)) forState:UIControlStateNormal];
    [aboutBtn.titleLabel setFont:[UIFont systemFontOfSize:18.0f]];
    [aboutBtn.titleLabel setTextColor:[UIColor whiteColor]];
    [aboutBtn setTitle:@"关  于  我  们" forState:UIControlStateNormal];
    [self.view addSubview:aboutBtn];
    
    UIButton* delCacheBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 185, 300, 40)];
    [delCacheBtn setBackgroundImage:createImageWithColor(HEXCOLOR(0xb3b3b3)) forState:UIControlStateNormal];
    [delCacheBtn setTitle:@"清  理  缓  存" forState:UIControlStateNormal];
    [delCacheBtn.titleLabel setFont:[UIFont systemFontOfSize:18.0f]];
    [delCacheBtn addTarget:self action:@selector(cleanCacheData) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:delCacheBtn];
}

-(void)cleanCacheData
{
    
}

-(void)changePushStatus:(UIButton*)sender
{
    [sender setSelected:!sender.isSelected];
    UIImageView* pointView = [sender viewWithTag:5001];
    [pointView setFrame:sender.isSelected?CGRectMake(0, 0, 32, 32):CGRectMake(45, 0, 32, 32)];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
